// import { baseFun } from './require'
import { instance as baseFun } from './require'

export async function getTodoList() {
  try {
    return await baseFun('/list')
  } catch (error) {
    console.error(error)
    return null
  }
}

export async function addTodo(data: unknown) {
  try {
    return await baseFun('/list', {
      method: 'POST',
      body: JSON.stringify(data),
      headers: {
        'Content-Type': 'application/json; charset=utf-8'
      }
    })
  } catch (error) {
    return null
  }
}

export async function updateTodo(id: number, data: unknown) {
  try {
    return await baseFun(`/list/${id}`, {
      method: 'PATCH',
      body: JSON.stringify(data),
      headers: {
        'Content-Type': 'application/json; charset=utf-8'
      }
    })
  } catch (error) {
    return null
  }
}

export async function deleteTodo(id: number) {
  try {
    return await baseFun(`/list/${id}`, {
      method: 'DELETE'
    })
  } catch (error) {
    return null
  }
}
